package projet.ejb;

import java.util.Collection;
import java.util.Date;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import projet.entity.Levee;
import projet.entity.Participation;
import projet.entity.Startup;

@Stateless
public class LeveeFacadeEJB implements LeveeFacade {
	@PersistenceContext(unitName = "SampleUnit")
	protected EntityManager entityMgr;
	
	public Levee add(Levee l) {
		entityMgr.persist(l);
		return l;
	}
	
	@SuppressWarnings("unchecked")
	public Collection<Levee> findAll() {
		 return entityMgr.createQuery("SELECT l FROM Levee as l").getResultList();
	}

	public void deleteAll() {
		Collection<Levee> l_levee = findAll();
		for(Levee l : l_levee){
			entityMgr.remove(l);
		}
	}

	@Override
	public Levee update(Levee l) {
		return entityMgr.merge(l);
	}
}
